package com.codeyang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codeyang.domain.OperLog;
import com.codeyang.dto.OperLogDto;
import com.codeyang.mapper.OperLogMapper;
import com.codeyang.service.OperLogService;
import com.codeyang.vo.DataGridView;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 描述: TO-删除标志-DO
 *
 * @author CodeYang_Site
 * @version 2021/4/20 15:34
 */
@Service
public class OperLogServiceImpl extends ServiceImpl<OperLogMapper, OperLog> implements OperLogService {

    @Autowired
    private OperLogMapper operLogMapper;

    @Override
    public DataGridView lisPage(OperLogDto operLogDto) {
        Page<OperLog> page = new Page<>(operLogDto.getPageNum(), operLogDto.getPageSize());
        // 按操作时间排序
        page.addOrder(OrderItem.desc(OperLog.COL_OPER_TIME));
        QueryWrapper<OperLog> qw = new QueryWrapper<>();
        //  五个条件
        qw.like(StringUtils.isNotBlank(operLogDto.getTitle()), OperLog.COL_TITLE, operLogDto.getTitle());
        qw.like(StringUtils.isNotBlank(operLogDto.getOperName()), OperLog.COL_OPER_NAME, operLogDto.getOperName());
        qw.eq(StringUtils.isNotBlank(operLogDto.getBusinessType() ), OperLog.COL_BUSINESS_TYPE, operLogDto.getBusinessType());
        qw.eq(StringUtils.isNotBlank(operLogDto.getStatus()), OperLog.COL_STATUS, operLogDto.getStatus());
        qw.between(operLogDto.getBeginTime() != null && operLogDto.getEndTime() != null, OperLog.COL_OPER_TIME, operLogDto.getBeginTime(), operLogDto.getEndTime());

        operLogMapper.selectPage(page, qw);

        return new DataGridView(page.getTotal(), page.getRecords());
    }
}
